package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsOrderXianService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsOrderXianForm;
import com.youlai.boot.system.model.query.LpsOrderXianQuery;
import com.youlai.boot.system.model.vo.LpsOrderXianVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 新产品 线前端控制层
 *
 * @author lwb
 * @since 2025-07-14 16:24
 */
@Tag(name = "新产品 线接口")
@RestController
@RequestMapping("/api/v1/lpsOrderXians")
@RequiredArgsConstructor
public class LpsOrderXianController  {

    private final LpsOrderXianService lpsOrderXianService;

    @Operation(summary = "新产品 线分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXian:query')")
    public PageResult<LpsOrderXianVO> getLpsOrderXianPage(LpsOrderXianQuery queryParams ) {
        IPage<LpsOrderXianVO> result = lpsOrderXianService.getLpsOrderXianPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增新产品 线")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXian:add')")
    public Result<Void> saveLpsOrderXian(@RequestBody @Valid LpsOrderXianForm formData ) {
        boolean result = lpsOrderXianService.saveLpsOrderXian(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取新产品 线表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXian:edit')")
    public Result<LpsOrderXianForm> getLpsOrderXianForm(
        @Parameter(description = "新产品 线ID") @PathVariable Long id
    ) {
        LpsOrderXianForm formData = lpsOrderXianService.getLpsOrderXianFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改新产品 线")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXian:edit')")
    public Result<Void> updateLpsOrderXian(
            @Parameter(description = "新产品 线ID") @PathVariable Long id,
            @RequestBody @Validated LpsOrderXianForm formData
    ) {
        boolean result = lpsOrderXianService.updateLpsOrderXian(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除新产品 线")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXian:delete')")
    public Result<Void> deleteLpsOrderXians(
        @Parameter(description = "新产品 线ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsOrderXianService.deleteLpsOrderXians(ids);
        return Result.judge(result);
    }
}
